//
//  UIBarButtonItem+Extension.swift
//  Faner_Weibo
//
//  Created by 范英强 on 16/1/26.
//  Copyright © 2016年 范英强. All rights reserved.
//

import UIKit

//button字体抽取常量

let ItemTitleFontSize: CGFloat = 14

extension UIBarButtonItem{
    
    
    convenience init(imgName: String? = nil ,title: String? = nil,target: AnyObject?, action: Selector) {
        self.init()
        let button = UIButton(type: UIButtonType.Custom)
        if let img = imgName {
            button.setImage(UIImage(named: img), forState: UIControlState.Normal)
            button.setImage(UIImage(named: "\(img)_highlighted"), forState: UIControlState.Highlighted)
        }
        
        if let tit = title {
            button.setTitle(tit, forState: UIControlState.Normal)
            button.titleLabel?.font = UIFont.systemFontOfSize(ItemTitleFontSize);
            button.setTitleColor(UIColor(white: 80 / 255, alpha: 1), forState: UIControlState.Normal)
            button.setTitleColor(UIColor.orangeColor(), forState: UIControlState.Highlighted)
        }
        button.addTarget(target, action: action, forControlEvents: UIControlEvents.TouchUpInside)
        button.sizeToFit()
        customView = button
    }
}